<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
//引入
use App\Admin\Test;
use Input;
class TestController extends Controller
{
    //列表操作
    public function index(){
    	//获取数据
    	$data = Test::where('isdel','=','2')->get();
    	//展示视图，并且传递数据
    	return view('admin.test.index',compact('data'));
    }


    public function add(){
    	if(Input::method() == 'POST'){
    		//写一些必要的验证
    		$data = Input::except('_token');
            $data['isdel'] = '2';
    		$data['addtime'] = date('Y-m-d H:i:s');
    		$result = Test::insert($data); //布尔值
    		//需要返回添加结果
    		return $result ? '1' : '0';
    	}else{
    		//展示视图
    		return view('admin.test.add');
    	}
    }

    public function edit(){
        if(Input::method() == 'POST'){
            //写一些必要的验证
            $data = Input::except('_token','updated_at');
            
            $result = Test::where('id',$data['id'])->update($data);
            //需要返回添加结果
            return $result ? '1' : '0';
        }else{
            //展示视图
            $id = $_GET['id'];  
            $data = Test::where('id','=',$id)->get();
            return view('admin.test.edit',compact('data'));
        }
    }


    public function del(){
        $id = $_GET['id'];  
        $info = Test::where('id','=',$id)->update(['isdel'=>1]);
        return $info ? '1' : '0';
    }

}
